<?php

namespace Database\Factories;

use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Room>
 */
class RoomFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'room_id' => 'room_' . time() . '_' . Str::random(4),
            'title' => fake()->words(3, true),
            'description' => fake()->sentence(),
            'type' => fake()->randomElement(['temporary', 'permanent']),
            'creator_id' => User::factory(),
            'menu_source' => fake()->randomElement(['default', 'template', 'custom']),
            'menu_template_id' => null,
            'settings' => [
                'autoClose' => fake()->boolean(),
                'maxOrderAmount' => fake()->numberBetween(100, 1000),
                'allowGuestOrder' => fake()->boolean(),
                'requireApproval' => fake()->boolean(),
                'showUserFavorites' => fake()->boolean(),
                'allowParticipantAdd' => fake()->boolean(),
                'allowParticipantSuggest' => fake()->boolean(),
            ],
            'expires_at' => fake()->optional(0.7)->dateTimeBetween('now', '+1 week'),
            'status' => fake()->randomElement(['active', 'closed', 'expired']),
            'max_participants' => fake()->numberBetween(10, 100),
            'current_round' => fake()->numberBetween(1, 10),
            'total_orders' => fake()->numberBetween(0, 50),
            'last_activity_at' => fake()->dateTimeBetween('-1 week', 'now'),
        ];
    }

    /**
     * 临时房间
     */
    public function temporary(): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => 'temporary',
            'expires_at' => fake()->dateTimeBetween('now', '+1 week'),
        ]);
    }

    /**
     * 永久房间
     */
    public function permanent(): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => 'permanent',
            'expires_at' => null,
        ]);
    }

    /**
     * 活跃房间
     */
    public function active(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => 'active',
        ]);
    }

    /**
     * 使用模板菜单的房间
     */
    public function withTemplate(): static
    {
        return $this->state(fn (array $attributes) => [
            'menu_source' => 'template',
            'menu_template_id' => MenuTemplate::factory(),
        ]);
    }
}
